package com.sk.bilibili.model.fragment.member;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.Coin;
import com.sk.bilibili.bean.Favorites;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.bean.Praise;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.CoinMapper;
import com.sk.bilibili.mapper.FavoritesMapper;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.PraiseMapper;
import com.sk.bilibili.mapper.VideoSetMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.member.HomeFragment;

import java.util.List;

public class HomeModel extends BaseModel<HomeFragment> {

    @Autowired
    VideoSetMapper videoSetMapper;
    @Autowired
    FavoritesMapper favoritesMapper;
    @Autowired
    FollowThemMapper followThemMapper;
    @Autowired
    CoinMapper coinMapper;
    @Autowired
    PraiseMapper praiseMapper;

    public void loadData(Integer memberId) {
        JsonMap map=new JsonMap();
        map.put("size",4);//最多获取4个
        map.put("memberId",memberId);
        RequestUtils.process(videoSetMapper.getVideoSets(map), videoSetPage ->
                view.loadVideoSuccess(videoSetPage.getRecords()));
        RequestUtils.process(favoritesMapper.getAll(memberId,2),
                favorites -> view.loadFavoritesSuccess(favorites));
        map=new JsonMap();//不能直接复用 会覆盖信息  异步的
        map.put("size",3);//最多获取3个
        map.put("memberId",memberId);
        RequestUtils.process(followThemMapper.getFollowThem(map),
                followThemPage -> view.loadFollowThemSuccess(followThemPage.getRecords()));
        map=new JsonMap();//不能直接复用 会覆盖信息  异步的
        map.put("size",2);//最多获取2个
        map.put("memberId",memberId);
        RequestUtils.process(coinMapper.getCoinVideo(map),
                coinPage -> view.loadCoinSuccess(coinPage.getRecords()));
        RequestUtils.process(praiseMapper.getPraiseVideo(map),
                praisePage -> view.loadPraiseSuccess(praisePage.getRecords()));
    }

}